package com.eastfair.imaster.controller;

import com.eastfair.imaster.entity.CustomerPoolLogs;
import com.eastfair.imaster.dto.CustomerPoolLogsSaveDTO;
import com.eastfair.imaster.dto.CustomerPoolLogsUpdateDTO;
import com.eastfair.imaster.dto.CustomerPoolLogsPageQuery;
import com.eastfair.imaster.service.CustomerPoolLogsService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 客户池操作记录表
 * </p>
 *
 * @author liuxiaobai
 * @date 2021-11-15
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/customerPoolLogs")
@Api(value = "CustomerPoolLogs", tags = "客户池操作记录表")
public class CustomerPoolLogsController extends SuperController<CustomerPoolLogsService, Long, CustomerPoolLogs, CustomerPoolLogsPageQuery, CustomerPoolLogsSaveDTO, CustomerPoolLogsUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<CustomerPoolLogs> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<CustomerPoolLogs> customerPoolLogsList = list.stream().map((map) -> {
            CustomerPoolLogs customerPoolLogs = CustomerPoolLogs.builder().build();
            //TODO 请在这里完成转换
            return customerPoolLogs;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(customerPoolLogsList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<CustomerPoolLogsPageQuery> params) {
        CustomerPoolLogsPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

}
